<template>
  <div>
    <div class="docker" style="height: 660px;overflow: hidden">
      <div div="container">
        <div class="row">
          <!-- nav -->
          <div class="nav">
            <a v-if="$auth.front_username == ''">
              <a style="color:#DE4323;margin-left: 150px;">
                <router-link to="/login">亲，请登录</router-link>
              </a>
              <a class="div">免费注册</a>
            </a>
            <a v-else>
              <a style="color:#DE4323;margin-left: 150px;">
                <router-link to="/login">用户: {{ $auth.front_username }}</router-link>
              </a>
              <a class="div" @click="Logout">登出</a>
            </a>
            <a style="margin-left: 400px;"></a>
            <a class="push"></a>
            <a class="push">
              <router-link to="/">科购首页</router-link>
            </a>
            <a class="push">
              <router-link to="/GoodsCar"><img src="../assets/car.png">&nbsp购物车</router-link>
            </a>
            <a class="push">
              <router-link to="/orderList">订单详情</router-link>
            </a>
            <a class="push">
              <router-link to="/Recharge">充值页面</router-link>
            </a>
            <a class="push">
              <router-link to="/feedback">用户反馈</router-link>
            </a>
            <a class="push"></a>
          </div>
          <!-- main -->
          <div class="main">
            <div class="logo">
              <h1>科购</h1>
              <p>KeGou</p>
            </div>
            <div class="box"
                 style="border: 1px solid #fff;background-color: #fff;width: 600px;height: 400px;border-radius: 4px;margin-left: 500px">
              <h1 style="font-size: 30px;text-align: center;margin-top: 20px;font-weight: bolder">用户充值</h1>

              <p style="font-size: 20px;font-weight: bolder;margin-left: 60px;margin-top: 20px">用户余额: {{ num }}</p>

              <div class="row">
                <el-button @click="Recharge(100)" type="primary"
                           style="width: 120px;margin-left: 60px;margin-top: 40px;height: 40px">100
                </el-button>
                <el-button @click="Recharge(200)" type="primary"
                           style="width: 120px;margin-left: 60px;margin-top: 40px;height: 40px">200
                </el-button>
                <el-button @click="Recharge(400)" type="primary"
                           style="width: 120px;margin-left: 60px;margin-top: 40px;height: 40px">400
                </el-button>
                <el-button @click="Recharge(600)" type="primary"
                           style="width: 120px;margin-left: 60px;margin-top: 40px;height: 40px">600
                </el-button>
                <el-button @click="Recharge(800)" type="primary"
                           style="width: 120px;margin-left: 60px;margin-top: 40px;height: 40px">800
                </el-button>
                <input type="text" v-model="value" placeholder="自定义"
                       style="padding-left:40px;width: 120px;margin-left: 60px;border: 1px solid #5A9CF8;border-radius: 4px;background-color:#5A9CF8;margin-top: 40px;height: 40px"
                ></input>
              </div>

              <button @click="UserMint"
                      style="width: 200px;height: 40px;background: #0f0;border: 1px solid #0f0;border-radius: 4px;margin-left: 190px;margin-top: 50px">
                充值
              </button>
            </div>

          </div>
        </div>
      </div>
    </div>
    <div class="footer">
      <p>反馈建议 | 官方空间 | 空间活动 | 空间应用 | ABCmouse腾讯版 | 腾讯原创馆 | QQ互联 | QQ登录 | 社交组件 | 应用侵权投诉 | Complaint Guidelines</p>
      <p>Copyright 2005 - 2022 Tencent.All Rights Reserved.</p>
      <p><a href="https://beian.miit.gov.cn">湘ICP备2022018153号-1</a></p>
    </div>
  </div>
</template>

<script>
import "bootstrap"
import qs from "qs";

export default {
  name: "Recharge",
  data() {
    return {
      value: 0,
      num: 0,
    }
  },
  methods: {
    //实现充值
    UserMint() {
      if (this.value > 0) {
        this.$http.post("/user/mint", qs.stringify({
          num: this.value,
          user: this.$auth.front_username
        }), {
          headers: {
            Authorization: "Bearer " + localStorage.getItem("front_token") //带着token去请求
          }
        }).then((rep) => {
          if (rep.data.code == 401) { //token 验证失败
            this.$router.push("/login")
            this.$notify.info({
              title: '系统信息',
              message: '请重新登陆'
            })
          } else {
            this.$notify.info({
              title: '系统信息',
              message: rep.data.msg
            }),
              this.GetUserAccount();
          }
        }).catch((rep) => {
          console.log(rep)
        })
      } else {
        this.$notify.info({
          title: '系统信息',
          message: '请输入正确金额'
        })
      }
    },
    //获取用户余额
    GetUserAccount() {
      this.$http.get("/user/GetUserAccount", {
        params: {
          user: this.$auth.front_username //用户
        },
        headers: {
          Authorization: "Bearer " + localStorage.getItem("front_token") //带着token去请求
        }
      }).then((rep) => {
        if (rep.data.code == 401) { //token 验证失败
          this.$router.push("/login")
          this.$notify.info({
            title: '系统信息',
            message: '请重新登陆'
          })
        } else {
          this.num = rep.data.num
        }
      }).catch((rep) => {
        console.log(rep)
      })
    },
    Recharge(num) {
      this.value = num
    },
    Logout() {
      this.$auth.delFrontAuth()
      this.$router.push("/login")
    },
  },
  mounted() {
    this.GetUserAccount();
  }
}
</script>

<style scoped>
* {
  padding: 0px;
  margin: 0px;
}

.docker {
  background-color: #EAE8EB;
}

.nav {
  border: 1px solid #F5F5F5;
  width: 100%;
  font-size: 10px;
  background-color: #F5F5F5;
}

.nav a {
  margin-top: 5px;
  margin-bottom: 5px;
  cursor: pointer;
}

.nav .div {
  margin-left: 30px;
  color: #8D8D8D;
}

.nav .push {
  margin-left: 30px;
  color: #8D8D8D;
}

.nav .push img {
  width: 15px;
  margin-left: 10px;
}

.logo {
  font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
  margin-left: 200px;
  margin-top: 40px;
  color: #EB5E2A;
}

.logo p {
  font-size: 20px;
  margin-top: -10px;
  margin-left: 9px;
}

.search input {
  border: 3px solid #EB5E2A;
  width: 650px;
  height: 45px;
  border-radius: 20px;
}

.search {
  margin-top: -75px;
  margin-left: 400px;
}

.button input {
  border: 1px solid #EB5E2A;
  width: 70px;
  background-color: #EB5E2A;
  color: #fff;
  font-weight: bolder;
  height: 36px;
  border-radius: 20px;
}

.button {
  margin-top: -40.5px;
  margin-left: 975px;
}

.container .row .title {
  border: 1px solid #fff;
  width: 32%;
  border-radius: 10px;
  background-color: #F7F9FA;
  height: 180px;
  margin-left: 11px;
  margin-top: 15px;
}

.container .row .title img {
  width: 150px;
  border-radius: 10px;
  margin-top: 12px;
  margin-left: 10px;
}

.container .row .title .name {
  margin-left: 175px;
  margin-top: -150px;
}

.container .row .title .money {
  margin-left: 180px;
  margin-top: 100px;
  color: #EB5E2A;
}

.container .row .title .money a {
  font-size: 24px;
}

.footer {
  margin-top: 20px;
  border: 1px solid #fff;
  text-align: center;
  font-size: 10px;
  background-color: #fff;
  padding-top: 10px;
  padding-bottom: 10px;
}

.footer p {
  margin-bottom: 0px;
}
</style>
